package com.holdtime.jtt809dataservice.client.config;

import com.holdtime.jtt809dataservice.client.runnable.BtjjXytParentPlatformClientLinkHandler;
import com.holdtime.jtt809dataservice.client.socket.TcpClient;
import com.holdtime.jtt809dataservice.common.Common;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * author: sunwei
 * Date: 2025/3/21 19:56
 * Description:
 */
@Slf4j
@Component
public class InitRunn implements CommandLineRunner {
    @Resource
    private TcpClient subordinatePlatformClient;
    @Resource
    private BtjjXytParentPlatformClientLinkHandler btjjXytParentPlatformClientLinkHandler;
    @Resource
    private BtjjXytParentPlatfromConfig btjjXytParentPlatfromConfig;

    @Override
    public void run(String... args) throws Exception {
        if (btjjXytParentPlatfromConfig.getStatus() == Common.PARENT_PLATFORM_LINK_STATUS_OPEN) {
            subordinatePlatformClient.setRunnable(btjjXytParentPlatformClientLinkHandler);
            subordinatePlatformClient.connect();
        }
    }
}
